package priv.winnine;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;

import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class RestfulParamsBuilder {

    private Map<String, Object> info;
    private Map<String, Object> subject;
    private String timestamp;
    private String data;

    public RestfulParamsBuilder() {
        info = new HashMap();
        subject = new HashMap();
    }

    public RestfulParamsBuilder addInfo(String key, Object value) {
        info.put(key, value);
        return this;
    }

    public RestfulParamsBuilder addSubject(String key, Object value) {
        subject.put(key, value);
        return this;
    }

    public RestfulParamsBuilder addData(String value) {
        this.data = value;
        return this;
    }

    public String buildJSON() throws JsonProcessingException {
        this.timestamp = String.valueOf(System.currentTimeMillis());
        return new ObjectMapper().writeValueAsString(this);
    }

    public String buildXML() throws JsonProcessingException {
        this.timestamp = String.valueOf(System.currentTimeMillis());
        return new XmlMapper().writeValueAsString(this);
    }

}
